﻿using BCT.Models;
using BCT.Repositories.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BCT.Repositories
{
    public class OccuManageRepository : IOccuManageRepository
    {
        public List<OccupationModel> GetOccupationList(RoleAndOccupationModel model) {
            using (var context = new EvaluateEntities())
            {
                var occupationlist = context.Occupation
                                     .Where(s => (context.RoleAndOccupation.Where(a => a.RoleId == model.RoleId).Select(a => a.OccupationId).ToList()).Contains(s.OccupationId))
                                     .Select(s => new OccupationModel
                                     {
                                         OccuId = s.OccupationId,
                                         OccuName = s.OccuName,
                                         Active = s.Active
                                     }).ToList();
                return occupationlist;
            }
        }

        //获取occupation的下拉列表
        public List<OccupationModel> GetOccupationSelect() {
            using (var context = new EvaluateEntities()) {
                var occupationlist = context.Occupation
                                     .Select(s => new OccupationModel{
                                         OccuId = s.OccupationId,
                                         OccuName = s.OccuName,
                                         Active = s.Active
                                     }).ToList();
                return occupationlist;
            }
        }
    }
}
